package main.com.cyz.Recursion;

/**
 * @author fox
 * @version 1.0
 * @description 插入排序 - 递归
 * @date 2024/5/17 10:44
 */
public class InsertSort {

    public void sort(int[] nums){
        r(nums,1);
    }

    private void r(int[] nums,int index){
        if (index == nums.length){
            return;
        }
        int i = index - 1;
        int num = nums[index];
        while(i >= 0 && nums[i] > num){
            nums[i + 1] = nums[i];
            i --;
        }
        if (i + 1 != index) {
            nums[i + 1] = num;
        }
        r(nums,index + 1);
    }

}
